The aim of this analysis is to evaluate restaurant hygiene trends across Manhattan, focusing on inspection scores and their variability by cuisine type and location. By leveraging interactive visualizations, the study provides insights into patterns of hygiene performance, identifying areas and cuisines that may require intervention.

NYC Restaurant Inspection Grade Score Ranges

This section introduces the scoring ranges used for NYC restaurant inspections. The grades are defined as follows:

grade_score_table <- data.frame(
  Grade = c("A", "B", "C"),
  `Score Range` = c("< 14", "14 - 27", "28 or more")
)
kable(
  grade_score_table,
  col.names = c("Grade", "Score Range")
)
Grade Score Range
A < 14
B 14 - 27
C 28 or more

Density Map of Inspection Scores

The interactive density map offers a dynamic visualization of average restaurant inspection scores across specific areas in Manhattan, enabling users to explore hygiene trends geographically. By clicking on points on the map, users can view the average inspection score associated with that location’s longitude and latitude. Created using plot_ly, the map was generated by filtering data to include only entries with valid latitude, longitude, and inspection scores. A Viridis color scale visually represents score variations, ranging from 0 (best) to 40 (worst). The hoverable text feature further enhances interactivity, providing users with an engaging and informative tool to analyze restaurant inspection scores across Manhattan.

geo_coord <- data %>%
  filter(
    !is.na(SCORE), 
    !is.na(Latitude), 
    !is.na(Longitude)
  ) %>%
  mutate(
    SCORE = as.numeric(SCORE),
    info = str_c(
      DBA,
      paste("Cuisine: ", `CUISINE DESCRIPTION`), 
      paste("Score: ", SCORE),
      sep = "<br />"
    )
  ) %>%
  select(Longitude, Latitude, SCORE, info)

map_density <- plot_ly(
  data = geo_coord,
  lat = ~Latitude,
  lon = ~Longitude,
  z = ~SCORE,
  type = "densitymapbox",
  colorscale = "Viridis",
  radius = 5,
  hovertext = ~info,
  zmin = 0,
  zmax = 40 
)

map_density <- map_density %>%
  layout(
    title = "Density Plot of Inspection Scores of Restaurant in Manhattan",
    mapbox = list(
      style = 'carto-positron', 
      zoom = 13,
      center = list(lon = -73.9712, lat = 40.7831)
    ),
    margin = list(r = 0, t = 30, b = 0, l = 0)
  )

map_density

Top 35 Cuisine Types by Average Inspection Scores

We created a bar chart to highlight the Top 35 Cuisine Types by Average Inspection Scores, showcasing cuisines ranked by their average inspection scores. Using data grouped by CUISINE DESCRIPTION, we calculated the mean score for each cuisine type. The chart features orange bars with purple borders for visual clarity, with cuisine types ordered from the highest to the lowest average scores.

filtered_data <- data %>%
  select(`CUISINE DESCRIPTION`, SCORE) %>%
  filter(!is.na(`CUISINE DESCRIPTION`) & !is.na(SCORE)) %>%
  mutate(SCORE = as.numeric(SCORE)) %>%
  filter(!is.na(SCORE)) 

top_cuisines <- filtered_data %>%
  group_by(`CUISINE DESCRIPTION`) %>%
  summarise(avg_score = mean(SCORE, na.rm = TRUE)) %>%
  arrange(desc(avg_score)) %>%
  slice(1:35)

top_cuisine_data <- filtered_data %>%
  filter(`CUISINE DESCRIPTION` %in% top_cuisines$`CUISINE DESCRIPTION`)

top_cuisine_data <- top_cuisine_data %>%
  mutate(`CUISINE DESCRIPTION` = factor(`CUISINE DESCRIPTION`,
                                        levels = top_cuisines$`CUISINE DESCRIPTION`))

plot_ly(
  data = top_cuisines,
  x = ~reorder(`CUISINE DESCRIPTION`, -avg_score),
  y = ~avg_score,
  type = "bar",
  marker = list(color = "orange", line = list(color = "purple", width = 1))
) %>%
  layout(
    title = "Top 35 Cuisine Types by Average Inspection Scores",
    xaxis = list(
      title = "Cuisine Description",
      tickangle = 45,
      tickfont = list(size = 8)
    ),
    yaxis = list(
      title = "Average Score"
    ),
    margin = list(b = 100),
    titlefont = list(size = 14, bold = TRUE)
  )


The results reveal that cuisines such as Bangladeshi, African, and Filipino have the highest average inspection scores, suggesting potential areas for hygiene improvement. In contrast, more common cuisines like Japanese and Mediterranean tend to have lower average scores, reflecting better hygiene practices. This visualization underscores which cuisines may benefit from targeted interventions to enhance hygiene standards.

Inspection Score Distribution for Top 35 Cuisine Types

We created a boxplot to illustrate the Inspection Score Distribution for Top 35 Cuisine Types, providing a detailed view of the variability in inspection scores for these cuisines. To achieve this, we filtered the data to include only the top cuisines based on average scores and generated boxplots for each cuisine type. These plots display the range, interquartile range (IQR), and outliers for inspection scores.

plot_ly(
  data = top_cuisine_data,
  x = ~`CUISINE DESCRIPTION`,
  y = ~SCORE,
  type = "box",
  boxpoints = "outliers",
  marker = list(color = "purple"),
  line = list(color = "orange")
) %>%
  layout(
    title = "Inspection Score Distribution for Top 35 Cuisine Types",
    xaxis = list(
      title = "Cuisine Description",
      tickangle = 45,
      tickfont = list(size = 8)
    ),
    yaxis = list(
      title = "Inspection Score"
    ),
    margin = list(b = 100),
    titlefont = list(size = 14, bold = TRUE)
  )


The results show that cuisines like Bangladeshi and African have wider score ranges, higher medians, and several outliers, reflecting inconsistent hygiene performance. In contrast, cuisines such as Japanese and Mediterranean exhibit narrower distributions with lower medians, indicating consistent adherence to hygiene standards. This visualization complements the bar chart by emphasizing the variability in inspection scores, helping to identify cuisines with the most significant hygiene challenges.

Go Home